﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.AOPService.Core;
using A2DFramework.SQLDispatcherService;
using PostSharp.Aspects;

namespace A2DFramework.SQLDispatcherService
{
    [Serializable]
    public class SQLDispatcherHandler:OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionArgs args)
        {
            bool tagExist = true;
            SQLDispatcherAttribute attr = AOPHelper.CheckDefinationTag<SQLDispatcherAttribute>(args.Method, ref tagExist);
            if (!tagExist)
                attr = new SQLDispatcherAttribute(string.Empty);

            SQLDispatcherContext ctx = new SQLDispatcherContext();
            ctx.Region = attr.Region;
            SQLDispatcherContext.SetCurrentContext(ctx);
        }
        public override void OnExit(MethodExecutionArgs args)
        {
            SQLDispatcherContext.ResetCurrentContext();
        }
    }
}
